package com.laob.laob_special.common;

import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @author zhangh     
 * @version V1.0.0
 * @projectName laob_special
 * @title     IndexConfig   
 * @package    com.laob.laob_special.common  
 * @date   2019/9/10 19:07  
 * @explain 服务启动时自动打开网页
 */
@Configuration
public class IndexConfig {

    @EventListener({ApplicationReadyEvent.class})
    void applicationReadyEvent() {
        System.out.println("Portboy准备就绪 ... 启动浏览器");
        // 启动后访问地址
        String url = "http://localhost:8090";
        Runtime runtime = Runtime.getRuntime();
        try {
            runtime.exec("rundll32 url.dll,FileProtocolHandler " + url);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //
    //public static void main(String[] args) {
    //
    //    Method[] methods = IndexConfig.class.getDeclaredMethods();
    //    for (Method method : methods) {
    //        EventListener annotation = method.getAnnotation(EventListener.class);
    //
    //        if (annotation != null){
    //            System.out.println("value: "+ Arrays.toString(annotation.value()));
    //        }
    //    }
    //}

}
